<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script type="text/javascript">
  var combotreeVar;
  $(function() {
    var newOptions = {
      parentField : 'preId',
      multiple: true,
//			lines : true,
      panelHeight : 'auto',
      onLoadSuccess : function() {
        parent.$.messager.progress('close');
      }
    }
    combotreeVar = initComboTree('/roleController/rolesTree.html', $('#privilegs'), newOptions);

    $('#addFunction').click(function () {
      parent.$.messager.progress({
        title: '提示',
        text: '数据处理中，请稍后....'
      });
      var isValid = $('#form').form('validate');
      if (isValid) {
        parent.$.messager.progress('close');
       var treeChild = $('#privilegs').combotree('tree');
        var nodes1 = treeChild.tree('getChecked');
        var nodes2 = treeChild.tree('getChecked', 'indeterminate');
        var nodesObj = $.merge(nodes1,nodes2);
        var idArray = new Array();
        $.each(nodesObj,function(index, node){
          idArray.push(node.id +"");
        });
        var postData = {
          "roleName": $('#roleName').val(),
          "roleInfo": $('#roleInfo').val(),
          "choiceId": idArray
        };
        $.ajax({
          url: "${pageContext.request.contextPath}/roleController/addRole.html",
          type: "post",
          dataType: "json",
          data: postData,
          success: function (result) {
              parent.$.messager.progress('close');
              if (result && isSuccess(result.result)) {
                  parent.$.modalDialog.openner_treeGrid.datagrid('getPager').pagination('select');
                  parent.$.modalDialog.handler.dialog('close');
              }else{
                  parent.$.messager.alert('提示', result.result + " " + result.message, 'info');
              }
            return false;
          },
          error: function (result) {
//			internalError();
              templateInternalError(result.responseText);
              parent.$.messager.progress('close');
            return false;
          }
        });
      } else {
        parent.$.messager.progress('close');
        return isValid;
      }
    });
  });
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
  <div data-options="region:'center',border:false" title="" style="overflow: hidden;">
    <div id="form" method="post">
      <table class="table table-hover table-condensed">
        <tr>
          <%--<th>编号</th>--%>
          <%--<td><input name="id" type="text" class"span2" value="${role.id}" readonly="readonly"></td>--%>
          <th>角色名称</th>
          <td><input name="roleName" id="roleName" type="text" placeholder="请输入角色名称" class="easyui-validatebox span2" data-options="required:true" validType="unique" value=""></td>
        </tr>
        <tr>
          <%--<th>排序</th>--%>
          <%--<td><input name="seq" value="100" class="easyui-numberspinner" style="width: 140px; height: 29px;" required="required" data-options="editable:false"></td>--%>
          <th>配置权限</th>
          <td><select id="privilegs" name="choiceId" style="width: 140px; height: 29px;"></select>
            <img src="${pageContext.request.contextPath}/resources/style/images/extjs_icons/cut_red.png" onclick="$('#privilegs').combotree('clear');" />
          </td>
        </tr>
        <tr>
          <th>角色说明</th>
          <td colspan="3"><textarea name="roleInfo" id="roleInfo" rows="" cols="" class="span5"></textarea></td>
        </tr>
      </table>
    </div>
  </div>
</div>